﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lavanderia.Entities;

namespace Lavanderia.Repository
{
    public class HotelRepository :MasterRepository, IHotelRepository
    {
        public List<HOTEL> GetFromHoteles()
        {
            var query = from p in context.HOTELES
                select p;
            return query.ToList();
        }

        public List<HOTEL> GetFromHotelesByCriterio(string criterio)
        {
            var query = from p in context.HOTELES
                        select p;
            if (criterio!=null && criterio!=String.Empty && criterio!="")
            {
                query = from p in query
                    where p.NombreHotel.ToUpper().Contains(criterio.ToUpper()) ||
                          p.DireccionHotel.ToUpper().Contains(criterio.ToUpper())
                    select p;
            }
            return query.ToList();
        }

        public HOTEL GetHoteById(int id)
        {
            return context.HOTELES.Find(id);
        }

        public void AddHotel(HOTEL hotel)
        {
            context.HOTELES.Add(hotel);
            context.SaveChanges();
        }

        public void UpdateHotel(HOTEL hotel)
        {
            context.Entry(hotel).State = EntityState.Modified;
            context.SaveChanges();
        }

        public void RemoveHotel(int id)
        {
            var existe = context.HOTELES.Find(id);

            if (existe!=null)
            {
                context.HOTELES.Remove(existe);
                context.SaveChanges();
            }
        }
    }
}
